package output;

import PackagePoseidon.DistanceData;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JPanel;

public class OutputPanel extends JPanel implements Observer{
	
	private int xRobotPosition, yRobotPosition, heightPoint, widthPoint;
        private int xCenter,yCenter;
	private int thick;
	private Color color;
	
	public OutputPanel (){

		heightPoint    = 10;
		widthPoint   = 10;
		thick    = 1;
		color    = Color.BLACK;
		this.setPreferredSize(new Dimension(400,600));


        //I want start to the center
        xCenter = this.getWidth()/2;
        yCenter = this.getHeight()/2;
		repaint();
	}
	
	public void paint (Graphics g){
		Graphics2D g2d = (Graphics2D) g;
		g2d.setBackground(Color.WHITE);
		g2d.setColor(g2d.getBackground());
		
		//reset
		g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
		g2d.setColor(color);
		g2d.setStroke(new BasicStroke (thick));

        
		//Color new (x,y) robot position
    //    System.out.println( this.getWidth()/2);
     //   System.out.println( this.getHeight()/2);
        g2d.setColor(Color.RED);
        g2d.drawRect(xRobotPosition + this.getWidth()/2, yRobotPosition +this.getHeight()/2, widthPoint, heightPoint);

		
	}

		// o e' il CLIENT
		//ARG e' quello passato dal client con "notifyObservers"
	public void update(Observable o, Object data) {
 //       xyRobotPosition xy = (xyRobotPosition) arg;
  //      this.xRobotPosition = xy.x + xCenter;
   //     this.yRobotPosition = xy.y + yCenter;
   //       this.xRobotPosition = xCenter ;
   //       this.yRobotPosition = yCenter ;
        if (data instanceof DistanceData){
            DistanceData dataDis = (DistanceData)data;




            xRobotPosition =  Float.valueOf(dataDis.xDistance).intValue();
            yRobotPosition =  Float.valueOf(dataDis.xDistance).intValue();
            
            System.out.println(xRobotPosition);
            System.out.println(yRobotPosition);


        }
        repaint();
	}
}
